package com.dayuanit.dy15.atm.dto;

import com.dayuanit.dy15.atm.common.ResultCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


import java.util.HashMap;
import java.util.Map;


/**
 * @author echo
 * @date 2020/4/20 - 12:00
 */
@Data
public class ResponseDTO {


    //ApiModelProperty Swagger注解
    @ApiModelProperty(value = "是否成功")
    private Boolean success;


    @ApiModelProperty(value = "返回码")
    private Integer code;


    @ApiModelProperty(value = "返回消息")
    private String message;


    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();


    //构造方法私有
    private ResponseDTO() {
    }


    //成功
    public static ResponseDTO success() {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setSuccess(true);
        responseDTO.setCode(ResultCode.SUCCESS);
        responseDTO.setMessage("成功");
        return responseDTO;
    }

    //失败
    public static ResponseDTO error() {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setSuccess(false);
        responseDTO.setCode(ResultCode.ERROR);
        responseDTO.setMessage("失败");
        return responseDTO;
    }


    //return this; ResponseDTO.success().message...链式编程
    public ResponseDTO success(Boolean success) {
        this.setSuccess(success);
        return this;
    }


    public ResponseDTO message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResponseDTO code(Integer code) {
        this.setCode(code);
        return this;
    }


    public ResponseDTO data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }


    public ResponseDTO data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

}
